<?php

namespace App\Admin\Controllers;

use App\Models\AddressModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid;
use Encore\Admin\Grid\Filter;

class AddressController extends AdminController
{
    protected $title = '地址';

    /**
     * grid
     * @return Grid
     */
    protected function grid(): Grid
    {
        $grid = new Grid(new AddressModel);
        $grid->model()->orderByDesc('id');
        $grid->filter(function (Filter $filter) {
            $filter->disableIdFilter();
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('id', 'ID')->integer();
            });
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('user_id', '用户ID')->integer();
            });
        });
        $grid->column('id', 'ID')->sortable();
        $grid->column('user_id', '用户ID');
        $grid->column('contacts', '联系人');
        $grid->column('mobile', '联系电话');
        $grid->column('province_id', '省ID');
        $grid->column('city_id', '市ID');
        $grid->column('district_id', '区ID');
        $grid->column('province', '省');
        $grid->column('city', '市');
        $grid->column('district', '区');
        $grid->column('address', '详细地址');
        $grid->column('is_default', '默认地址')->using(__('l.whether'));
        $grid->column('is_return', '退货地址')->using(__('l.whether'));
        $grid->column('created_at', __('l.createdAt'));
        return $grid;
    }
}
